<?php

namespace App\Repositories;



use App\Interfaces\RecommendPositionService;
use App\Models\RecommendPosition;
use App\Models\Recommend;
use App\Models\Goods;

class RecommendPositionRepository implements RecommendPositionService{

	protected  $recommendPositionService;

	public function __construct(RecommendPosition $recommendPosition){

        $this->recommendPosition = $recommendPosition;

    }

    public function getAllRecommendPosition(){
    	$recommendAllPosition = RecommendPosition::where('is_recommend',1)->get();
    	return $recommendAllPosition;
    }


    public function getRecommendPosition($identification){

        $recommendPostion = RecommendPosition::where('identification',$identification)->where('is_recommend',1)->first();
        

        return $recommendPostion;

    

    }
    public function getRecommendGoods($identification){

    	$recommend_position_id = RecommendPosition::where('identification',$identification)->pluck('id');
        $recommend = Recommend::select('recommend.*','goods.market_price','goods.shop_price','goods.is_on_sale')
            ->join('goods','recommend.link','=','goods.goods_id')
            ->where('recommend.recommend_position_id',$recommend_position_id)
            ->where('goods.is_on_sale',1)
            ->orderBy('recommend.sort_order','desc')->get();
  
        return $recommend;
    }

    public function getRecommendByNumber($number,$identification){
        $recommend_position_id = RecommendPosition::where('identification',$identification)->pluck('id');
        $recommend = Recommend::select('recommend.*','goods.market_price','goods.shop_price','goods.is_on_sale')
            ->join('goods','recommend.link','=','goods.goods_id')
            ->where('recommend.recommend_position_id',$recommend_position_id)
            ->where('goods.is_on_sale',1)
            ->orderBy('recommend.sort_order','desc')->get()->take($number);

        return $recommend;
    }

    public function getRecommendByPage($identification,$page){
        $recommend_position_id = RecommendPosition::where('identification',$identification)->pluck('id');
        $recommend = Recommend::select('recommend.*','goods.market_price','goods.shop_price','goods.is_on_sale')
            ->join('goods','recommend.link','=','goods.goods_id')
            ->where('recommend.recommend_position_id',$recommend_position_id)
            ->where('goods.is_on_sale',1)
            ->orderBy('recommend.sort_order','desc')->paginate(4,['*'],'page',$page);;

        return $recommend;
    }

}